{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "from chemview import MolecularViewer\n",
    "\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# Drawing a water molecule\n",
    "mv = MolecularViewer(np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]),\n",
    "                     {'atom_types': ['H', 'O', 'H'],\n",
    "                      'bonds': [[0, 1], [1, 2]]},\n",
    "                     width = 300,\n",
    "                     height = 300)\n",
    "#mv.points()\n",
    "#mv.lines()\n",
    "mv.ball_and_sticks()\n",
    "mv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "mv.coordinates = mv.coordinates + 0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# We use MDTraj to get a secondary structure\n",
    "import mdtraj as md\n",
    "traj = md.load_pdb('../tests/data/2M6K.pdb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# We build our version of topology\n",
    "\n",
    "top = {}\n",
    "top['atom_types'] = [a.element.symbol for a in traj.topology.atoms]\n",
    "top['atom_names'] = [a.name for a in traj.topology.atoms]\n",
    "top['bonds'] = [(a.index, b.index) for a, b in traj.topology.bonds]\n",
    "top['secondary_structure'] = md.compute_dssp(traj[0])[0]\n",
    "top['residue_types'] = [r.name for r in traj.topology.residues ]\n",
    "top['residue_indices'] = [ [a.index for a in r.atoms] for r in traj.topology.residues ]\n",
    "\n",
    "mv = MolecularViewer(traj.xyz[0], top)\n",
    "# mv.cylinder_and_strand()\n",
    "# mv.cartoon()\n",
    "# mv.autozoom(traj.xyz[0])\n",
    "mv.line_ribbon()\n",
    "#mv.wireframe()\n",
    "mv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "from chemview.widget import TrajectoryControls\n",
    "\n",
    "tc = TrajectoryControls(traj.n_frames)\n",
    "\n",
    "def update(*args):\n",
    "    mv.coordinates = traj.xyz[tc.frame]\n",
    "\n",
    "tc.observe(update, \"frame\")\n",
    "tc.fps = 10\n",
    "tc"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
